#include <iostream>

using namespace std;
// declare and initiate three pseudo constants
const int ROW=15,COLUMN=10,N=4;
int russia_block[ROW+1][COLUMN],block[N][N];
// declare a struct array to store the row and column index of blocks which equal 1
struct
{
    int row,column;
} coordinate[N];

int main_46()
{
    for (int i=0; i<ROW ; i++ )
    {
        for (int j=0; j<COLUMN ; j++ )
        {
            cin>>russia_block[i][j];
        }
    }
    for (int i=0; i<N ; i++ )
    {
        for (int j=0; j<N ; j++ )
        {
            cin>>block[i][j];
        }
    }
    // assign 1 to  all the elements of the last row to simplify the logic complexity of algorithm.
    for (int i=0; i<COLUMN ; i++ )
    {
        russia_block[ROW][i]=1;
    }
    int column,k=0,row;
    cin>>column;
    //assign the row and column index of blocks which equal 1 to the kth struct.
    for (int i=0; i<N ; i++ )
    {
        for (int j=0; j<N ; j++ )
        {
            if (block[i][j]==1)
            {
                coordinate[k].row=i;
                coordinate[k].column=j;
                k++;
            }
        }
    }
    //convert the column to the column index relative to Russia Block matrix
    column--;
    bool flag;
    // The row starts from 1 which is the row index next only to the one relative to the block
    for (row=1; row<16; row++ )
    {
        // reassign false to the flag which stands for the exit condition of the outer for loop.
        flag=false;
        for (int i=0; i<N ; i++ )
        {
            if (russia_block[row+coordinate[i].row][column+coordinate[i].column]==1)
            {
                // change the flag to true which stands for the existence of 1 below the ith block
                flag=true;
            }
        }
        if (flag)
        {
            break;
        }
    }
    // let the row minus one in order to get the row index relative to Russia Block matrix
    row--;
    // fill the block
    for (int i=0; i<N ; i++ )
    {
        russia_block[row+coordinate[i].row][column+coordinate[i].column]=1;
    }
    // print
    for (int i=0;i<ROW ;i++ )
    {
        for (int j=0;j<COLUMN ;j++ )
        {
            cout<<russia_block[i][j]<<" ";
        }
        printf("\n");
    }
    return 0;
}
